<?php

class User_Model extends Model{
	
	private $id_user;
	private $name_user;
	private $email_user;
	private $pass_user;
	
	private $sqlInsert = "INSERT INTO user (name_user,email_user,pass_user) VALUES ('%s','%s','%s')";
	//private $sqlUpdate = "UPDATE user SET name_user='%s',email_user='%s',$pass_user='%s' WHERE id_user='%s'";
	private $sqlDelete = "DELETE FROM user WHERE id_user='%s'";
	private $sqlSelect = "SELECT * FROM user WHERE 1=1 %s %s";
	
	public function setIdUser($id_user){
		$this->id_user = trim(strip_tags($id_user));
	}
	
	public function setNameUser($name_user){
		$this->name_user = trim(strip_tags($name_user));
	}
	
	public function setEmailUser($email_user){
		$this->email_user = trim(strip_tags($email_user));
	}
	
	public function setPassUser($pass_user){
		 $pass = trim(strip_tags($pass_user));
		 $pass = md5($pass);
		 $this->pass_user = $pass;
	}
	
	public function getIdUser(){
		return $this->id_user;	
	}
	
	public function getNameUser(){
		return $this->name_user;	
	}
	
	public function getEmailUser(){
		return $this->email_user;	
	}
	
	public function getPassUser(){
		return $this->pass_user;	
	}
	
	public function insert(){
		$sql = sprintf($this->sqlInsert,$this->getNameUser(),$this->getEmailUser(),$this->getPassUser());
		return $this->runQuery($sql);
	}
	
	public function update(){
		$sql = sprintf($this->sqlUpdate,$this->getNameUser(),$this->getEmailUser(),$this->getPassUser(),
			           $this->getIdUser());
		return $this->runQuery($sql);
	}
	
	public function delete(){
		$sql = sprintf($this->sqlDelete,$this->getIdUser());
		return $this->runQuery($sql);
	}
	
	public function select($where='',$order=''){
		$sql = sprintf($this->sqlSelect,$where,$order);
		return $this->runSelect($sql);
	}
	
	public function selectCadastro($where='',$order=''){
		$sql = sprintf($this->sqlSelect,$where,$order);
		return $this->runEntrar($sql);
	}
	
	public function load(){
		$where = sprintf("AND id_user='%s'",$this->getIdUser());
		$row = $this->select($where);
		$this->setIdUser($row[0]['id_user']);
		$this->setNameUser($row[0]['name_user']);
		$this->setEmailUser($row[0]['email_user']);
		$this->setPassUser($row[0]['pass_user']);
		return $this;
	}
	
	public function loadCadastro(){
		$where = sprintf("AND email_user='%s'",$this->getEmailUser());
		return $this->selectCadastro($where);
	}
	
}

?>